package pers.ascend.spring.cloud.greenwich.service.governance.eureka.consumer.ribbon.manage.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.validation.constraints.NotBlank;

/**
 * 说明：
 *
 * @author ascend
 * 2021/3/16 8:05
 */
@RestController
@RequestMapping(value = "/consumer")
@Validated
public class EurekaConsumerRibbonController {
    protected Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/hello")
    public String hello(@RequestParam("name") @NotBlank String name) {
        if (log.isInfoEnabled()) {
            log.info("ConsumerController.hello()");
        }
        String url = "http://eureka-producer/producer/hello?name=" + name;
        return restTemplate.getForObject(url, String.class);
    }
}
